//
//  CardView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/6/5.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "CardView.h"

@interface CardView()
@property(nonatomic,strong) UIView *blckView;
@property (nonatomic,strong)UIImageView *seletedImg;
@property (weak, nonatomic) IBOutlet UIImageView *img1;
@property (weak, nonatomic) IBOutlet UIImageView *img2;
@property (weak, nonatomic) IBOutlet UIImageView *img3;
@end


@implementation CardView

+(instancetype)createView;
{
    return  [[[NSBundle mainBundle]loadNibNamed:@"CardView" owner:nil options:nil]lastObject];
    
}
-(void)showhighlighted:(NSString *)str
{
    if ([str isEqualToString:@"护照"]) {
        
        self.img2.highlighted = YES;
        self.seletedImg = self.img2;
        self.img1.highlighted = NO;
        self.img3.highlighted = NO;
    }else if([str isEqualToString:@"港澳通行证"]){
        self.img3.highlighted = YES;
        self.seletedImg = self.img3;
        self.img2.highlighted = NO;
        self.img1.highlighted = NO;
    }else
    {
        self.img1.highlighted = YES;
        self.seletedImg = self.img1;
        self.img2.highlighted = NO;
        self.img3.highlighted = NO;
    }
}


-(void)showInView:(UIView*)view{
    
    if (!self.blckView) {
        self.blckView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        [self.blckView setBackgroundColor:[UIColor blackColor]];
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [self.blckView addGestureRecognizer:singleTap];
    }
    
    
    
    CGRect buf = self.frame;
    buf.size.width = view.frame.size.width;
    buf.origin.y = view.frame.size.height;
    [self setFrame:buf];
    
    [self.blckView setAlpha:0];
    
    buf.origin.y = view.frame.size.height - buf.size.height;
    [view addSubview:self.blckView];
    [view addSubview:self];
    
    [UIView animateWithDuration:0.2 animations:^{
        
        
        [self.blckView setAlpha:0.6];
        
        [self setFrame:buf];
        
        
    } completion:^(BOOL finished) {
        
    }];
}

-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
    
    [self hide];
}

-(Boolean)isShow{
    
    return [self superview]!=nil;
}


-(void)hide{
    
    CGRect buf = self.frame;
    buf.origin.y += buf.size.height;
    [UIView animateWithDuration:0.2 animations:^{
        
        [self.blckView setAlpha:0];
        
        [self setFrame:buf];
        
    } completion:^(BOOL finished) {
        
        [self.blckView removeFromSuperview];
        [self removeFromSuperview];
    }];
}
- (IBAction)btnOnClick:(UIButton *)sender {
     [self endEditing:YES];
    
    if (sender.tag == 0) {//
        
    }else if(sender.tag == 1){
        
        self.seletedImg.highlighted = NO;
        self.seletedImg = self.img1;
        self.seletedImg.highlighted = YES;
   
    }else if (sender.tag == 2)
    {
        self.seletedImg.highlighted = NO;
        self.seletedImg = self.img2;
        self.seletedImg.highlighted = YES;
        
    }else if (sender.tag == 3)
    {
        self.seletedImg.highlighted = NO;
        self.seletedImg = self.img3;
        self.seletedImg.highlighted = YES;
    }
}

-(NSString *)getInfo
{
    if (self.seletedImg == self.img1) {
        return @"身份证";
    }else if (self.seletedImg == self.img2)
    {
        return @"护照";
    }else if (self.seletedImg == self.img3)
    {
        return @"港澳通行证";
    }
    return nil;
}


@end
